package com.lanou.controller;

import com.lanou.bean.Area;

import com.lanou.bean.HousingEstate;
import com.lanou.bean.Owner;
import com.lanou.service.AreaService;
import com.lanou.service.HousingEstateService;

import com.lanou.service.OwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
public class OwnerController {

    @Autowired
    private AreaService areaService;

    @Autowired
    private HousingEstateService housingEstateService;

    @Autowired
    private OwnerService ownerService;

    @RequestMapping("/regist")
    public List<Area> OwnerRegist(String code){
        System.out.println(code);
        return areaService.selectAllParent(code);
    }


    @RequestMapping("/getCity")
    public List<HousingEstate> getHousingEstateByCityCode(String citycode){
        System.out.println(citycode);
        System.out.println(housingEstateService.getHousingEstateByCityCode(citycode));
        return housingEstateService.getHousingEstateByCityCode(citycode);
    }


    @RequestMapping("/insertOwner")
    public int insertOwner(String owner){
        String[] strings = owner.split("/");
        Owner owner1=new Owner();
        owner1.setName(strings[0]);
        owner1.setIdcard(strings[1]);
        owner1.setSex(strings[2]);
        owner1.setTel(strings[3]);
        owner1.setHousingEstateCode(strings[4]);
        owner1.setAddress(strings[5]);
        System.out.println("获取的openid-----------"+strings[6]);
        owner1.setOpenid(strings[6]);
        owner1.setCreateTime(new Date());
        int insert = ownerService.insert(owner1);
        System.out.println(insert);
        return insert;
    }

}
